@startuml
participant "Application\nCode" as A

skinparam Participant {
  RoundCorner 10

  BackgroundColor<<LLMRails>> 76b900
  FontColor<<LLMRails>> white
  BorderColor<<LLMRails>> green
}


participant "Programmable\nGuardrails" as LLMRails <<LLMRails>>
participant "Input\nRails" as IR <<LLMRails>>
participant "Dialog\nRails" as DR <<LLMRails>>
participant "Output\nRails" as OR <<LLMRails>>
participant "Retrieval\nRails" as RR <<LLMRails>>
participant "Execution\nRails" as ER <<LLMRails>>
participant KB
participant Actions
participant "LLM"


Activate A
A->LLMRails: <<USER MESSAGE>>
activate LLMRails

LLMRails->IR: <<USER MESSAGE>>
activate IR

group [Optional] Input Rails can use actions
IR->Actions
activate Actions
return
end

group [Optional] Input Rails can use the LLM
IR->LLM
activate LLM
return
end

return Continue/Stop

LLMRails->DR: <<USER MESSAGE>>
activate DR

group If a Knowledge Base is used
DR->KB: <<QUERY>>
activate KB
return <<RELEVANT CHUNKS>>
DR->RR: <<RELEVANT CHUNKS>>
activate RR
return Continue/Alter/Stop
end

group [Optional] Dialog rails can use actions
DR->ER: <<ACTION/PARAMS>>
activate ER

ER->Actions: <<ACTION/PARAMS>>
activate Actions
return <<RESULT>>

group Optional
ER->LLM
activate LLM
return
end


return <<RESULT>>
end

DR->LLM: <<PROMPT>>
activate LLM
return <<COMPLETION>>

return <<BOT MESSAGE>>


LLMRails->OR: <<BOT MESSAGE>>
activate OR

group [Optional] Output Rails can use the LLM
OR->LLM
activate LLM
return
end

group [Optional] Output Rails can use actions
OR->Actions
activate Actions
return
end

return Continue/Stop


return #green <<BOT MESSAGE>>


'hide footbox
hide stereotype
scale 2
@enduml
